using Microsoft.SmallBasic.Library;

namespace SmallBasicFun
{
    /// <summary>
    /// The Tortoise allows you to draw lines and shapes by moving it around on the canvas
    /// </summary>
    [SmallBasicType]
    public static class Tortoise
    {
        public static MyTurtle turtle = new MyTurtle();

        static Tortoise()
        {
            ProgramWindow.Show();
        }
        public static void Reset()
        {
            turtle = new MyTurtle();
        }

        /// <summary>
        /// Sets the color drawn by the Tortoise. 
        /// See Also: Colors
        /// </summary>
        /// <example>Tortoise.SetPenColor("red")</example>
        /// <param name="color">
        /// the color of the pen
        /// </param>
        public static void SetPenColor(Primitive color)
        {
            turtle.LineColor = color.AsColor();
        }

        /// <summary>
        /// Gets color currently drawn by the Tortoise. The default is black.
        /// </summary>
        /// <example> lastColor = Tortoise.GetPenColor()</example>
        /// <returns>
        /// the color of the pen
        /// </returns>
        public static Primitive GetPenColor()
        {
            return turtle.LineColor.ToString();
        }

        /// <summary>
        /// Turns the Tortoise to face the given angle. 0 is Up, 180 is Down.
        /// </summary>
        /// <example> Tortoise.SetAngle(45)</example>
        public static void SetAngle(Primitive angle)
        {
            turtle.Angle = angle;
        }

        /// <summary>
        /// Sets the width of the pen drawn by the Tortoise. 
        /// </summary>
        /// <example> Tortoise.SetPenWidth(2)</example>
        /// <param name="widthInPixels">
        /// the width of the pen stroke
        /// </param>
        public static void SetPenWidth(Primitive widthInPixels)
        {
            turtle.LineWidth = widthInPixels;
        }

        /// <summary>
        /// Gets the width of the pen current drawn by the Tortoise. The default is 2.
        /// </summary>
        /// <example> penWidth = Tortoise.GetPenWidth()</example>
        /// <returns>
        /// the width of the pen stroke in pixels
        /// </returns>
        public static Primitive GetPenWidth()
        {
            return turtle.LineWidth;
        }

        /// <summary>
        /// Sets the speed the Tortoise moves. 
        /// </summary>
        /// <example> Tortoise.SetSpeed(8)</example>
        /// <param name="speed">
        /// The speed from 1 (slowest) to 10 (fastest)
        /// </param>
        public static void SetSpeed(Primitive speed)
        {
            turtle.Speed = speed;
        }

        /// <summary>
        /// Displays the Tortoise
        /// </summary>
        /// <example>Tortoise.Show()</example>
        public static void Show()
        {
            turtle.Show();
        }

        /// <summary>
        /// Completely hides the tortoise, not just his head. Of course, if you
        /// move him, you'll still see his trail.
        /// </summary>
        /// <example>Tortoise.Hide()</example>
        public static void Hide()
        {
            turtle.Hide();
        }

        /// <summary>
        /// Moves the Tortoise Forward the number of pixels specified. 
        /// </summary>
        /// <example> Tortoise.Move(50)</example>
        /// <param name="lengthInPixels">
        /// The number of pixels to move. Negative numbers will move the Tortoise backwards.
        /// </param>
        public static void Move(Primitive lengthInPixels)
        {
            turtle.Move(lengthInPixels);
            //MoveFast(lengthInPixels);
        }


        /// <summary>
        /// Moves the Tortoise to the X,Y coordinate requested. 
        /// </summary>
        /// <example> Tortoise.MoveTo(0,0)</example>
        /// <param name="x"> The X coordinate </param>
        /// <param name="y"> The Y coordinate </param>
        public static void MoveTo(Primitive x, Primitive y)
        {
            turtle.MoveTo(x, y);
        }

        /// <summary>
        /// Turns the Tortoise to the right (clockwise) the degrees specified. 
        /// </summary>
        /// <example> Tortoise.Turn(90)</example>
        /// <param name="degrees">
        /// The degrees to turn. Negative numbers will move the Tortoise to the left (counter-clockwise)
        /// </param>
        public static void Turn(Primitive degrees)
        {
            turtle.Turn(degrees);
        }

     

        /// <summary>
        /// Gets the X location of the Tortoise. The default is 320.
        /// </summary>
        /// <example>x = Tortoise.GetX()</example>
        /// <returns>The X location of the Tortoise</returns>
        public static Primitive GetX()
        {
            return turtle.X;
        }

        /// <summary>
        /// Sets the X location of the Tortoise
        /// The Tortoise instantly moves there, without drawing a line
        /// </summary>
        /// <example>Tortoise.SetX(10)</example>
        /// <param name="x">The X location</param>
        public static void SetX(Primitive x)
        {
            turtle.X = x;
        }

        /// <summary>
        /// Sets the Y location of the Tortoise
        /// The Tortoise instantly moves there, without drawing a line
        /// </summary>
        /// <example>Tortoise.SetY(10)</example>
        /// <param name="y">The Y location</param>
        public static void SetY(Primitive y)
        {
            turtle.Y = y;
        }

        /// <summary>
        /// Gets the Y location of the Tortoise. The default is 240.
        /// </summary>
        /// <example>y = Tortoise.GetY()</example>
        /// <returns>The y location of the Tortoise</returns>
        public static Primitive GetY()
        {
            return turtle.Y;
        }

        /// <summary>
        /// Gets Angle the Tortoise is Point. Up is 0 dergrees. The default is 0 (aiming up).
        /// </summary>
        /// <example>angle = Tortoise.GetAngle()</example>
        /// <returns>The Angle the Tortoise is Facing</returns>
        public static Primitive GetAngle()
        {
            return turtle.Angle;
        }

        /// <summary>
        /// Gets the current speed of the Tortoise. The default is 5.
        /// </summary>
        /// <example>speed = Tortoise.GetSpeed()</example>
        /// <returns>The current speed of the Tortoise</returns>
        public static Primitive GetSpeed()
        {
            return turtle.Speed;
        }

        public static void SetPosition(int x, int y)
        {
           SetX(x);
           SetY(y);
        }

        /// <summary>
        /// When the pen is up, the tortoise does not leave a trail. 
        /// </summary>
        /// <example>Tortoise.PenUp()</example>
        public static void PenUp()
        {
            turtle.PenDown = false;
        }
        /// <summary>
        /// When the pen is down, the tortoise leaves a trail. 
        /// </summary>
        /// <example>Tortoise.PenDown()</example>
        public static void PenDown()
        {
            turtle.PenDown = true;
        }

        public static void SetOrientation(int x, int y, int angle)
        {
            SetPosition(x,y);
            SetAngle(angle);
        }

        public static void InstantSpeed(bool goFast)
        {
            MyTurtle.forceAnimateTime = goFast ? 0.0 : (double?) null;
        }
    }
}